package leetcode.code1839;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	static char[] dics = new char[] { 'a', 'e', 'i', 'o', 'u' };
	static int limit;
	static {
		limit = 0;
		for (int i = 0; i < dics.length; i++) {
			limit |= 1 << (dics[i] - 'a');
		}
	}

	public int longestBeautifulSubstring(String word) {
		char[] cs = word.toCharArray();
		int cnt = 1;
		int ans = 0;
		int exist = (1 << (cs[0] - 'a'));
		for (int i = 1; i < cs.length; i++) {
			char c = cs[i];
			if (c >= cs[i - 1]) {
				cnt += 1;
			} else {
				if (exist == limit) {
					ans = Math.max(ans, cnt);
				}
				cnt = 1;
				exist = 0;
			}
			exist |= (1 << (c - 'a'));
		}
		if (exist == limit) {
			ans = Math.max(ans, cnt);
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(5, this.longestBeautifulSubstring("aeiou"));
		H.compare(13, this.longestBeautifulSubstring("aeiaaioaaaaeiiiiouuuooaauuaeiu"));
		H.compare(5, this.longestBeautifulSubstring("aeeeiiiioooauuuaeiou"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
